home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mgabra.zip / MGMMACS.ASM < prev    next >
Assembly Source File  |  1988-04-17  |  14KB  |  527 lines

  1. ;------------------------------------------------
  2. ; WHMACS - Assembly Language Macros
  3. ;------------------------------------------------
  4.  
  5. ;----------------------------------------------------------
  6. ; SAVREGS - Save 8086 Registers To Tcb (task control block)
  7. ;----------------------------------------------------------
  8.  
  9. SAVREGS MACRO   TASK
  10.         mov     [TASK], 0    ;0 means process put to sleep
  11.         mov     [TASK+2], ax
  12.         mov     [TASK+4], bx
  13.         mov     [TASK+6], cx
  14.         mov     [TASK+8], dx
  15.         mov     [TASK+10], bp
  16.         mov     [TASK+12], di
  17.         mov     [TASK+14], si
  18.         mov     [TASK+16], es
  19.         mov     [TASK+18], ds
  20.         pop     [TASK+24]       ;ip
  21.         pop     [TASK+26]       ;cs
  22.         pop     [TASK+28]       ;flags
  23.         mov     [TASK+20], ss
  24.         mov     [TASK+22], sp
  25.         ENDM
  26.  
  27. ;----------------------------------------------------
  28. ; SAVCUR - Save Cursor Position To Tcb. We use direct
  29. ; hardware because some program bypass the bios and
  30. ; give an innaccurate cursor position.
  31. ;----------------------------------------------------
  32.  
  33. SAVCUR  MACRO   TASK
  34. ;    mov    dx, add6845    ;find 6845 controller
  35. ;    mov    al, 14        ;register number
  36. ;    out    dx, al        ;do it
  37. ;    inc    dx        ;set for next register
  38. ;    in    al, dx
  39. ;    mov    ah, al
  40. ;    dec    dx              ;reset dx
  41. ;    mov    al, 15        ;port number
  42. ;    out    dx, al
  43. ;    inc    dx
  44. ;    in    al, dx
  45. ;    and    ax, 07ffh
  46. ;    mov    bl, 80
  47. ;    div    bl
  48. ;    xchg    ah, al
  49. ;       mov     [TASK+30], ax    ;save cursor location
  50.     mov    bx, 0
  51.     push    bx
  52.     pop    es            ;set segment
  53.     mov    bx, 0462h        ;page number in low ram
  54.     mov    bh, byte ptr es:[bx]    ;get it
  55.     mov    ah, 3
  56.     int    10h
  57.     mov    [TASK+30], dx        ;cursor position
  58.     mov    [TASK+52], cx        ;cursor size
  59.         ENDM
  60.  
  61. ;------------------------------------------------
  62. ; RESCUR - Restore Cursor Address From Tcb
  63. ;------------------------------------------------
  64.  
  65. RESCUR  MACRO   TASK
  66.     LOCAL    LB1, LB2
  67.     mov    ax, cs:scrswp    ;get screen swap mode
  68.     and    ax, 1        ;is cursor swapping enabled?
  69.     jnz     LB2        ;yes then do it
  70.     mov    ax, cs:scrswp    ;check again
  71.     and    ax, 8        ;cursor swap on key switch?
  72.     jz    LB1        ;if not then exit
  73.     cmp    cs:keyswap, 1    ;was it done on a keyswap?
  74.     jne    LB1        ;no then exit
  75. LB2:
  76.         mov     dx, [TASK+30]    ;cursor row and column to dx
  77.     mov    bh, byte ptr [TASK+51]    ;page number
  78.         mov     ah, 2        ;set cursor address function number
  79.         int     10h        ;call bios
  80.     mov    cx, [TASK+52]    ;cursror size
  81.     mov    ah, 1
  82.     int    10h
  83. LB1:
  84.         ENDM
  85.  
  86. ;------------------------------------------------
  87. ; SAVDTA - SAVE DTA ADDRESS TO TCB
  88. ;------------------------------------------------
  89.  
  90. SAVDTA  MACRO   TASK
  91.         mov     ah, 2fh        ;get dta address function number
  92.         int     21h        ;call dos
  93.         mov     [TASK+32], es    ;save dta address segment
  94.         mov     [TASK+34], bx    ;save dta offset
  95.         ENDM
  96.  
  97. ;------------------------------------------------
  98. ; SAV24H - Save Critical Error Address To Tcb
  99. ;------------------------------------------------
  100.  
  101. SAV24h  MACRO   TASK
  102.         SAVINT  24h, [TASK+36], [TASK+38]
  103.         ENDM
  104.  
  105. ;------------------------------------------------
  106. ; SAV23H - Save Control Break Handler
  107. ;------------------------------------------------
  108.  
  109. SAV23h    MACRO    TASK
  110.     SAVINT    23h, [TASK+46], [TASK+48]
  111.     ENDM
  112.  
  113. ;------------------------------------------------
  114. ; SAVPRC - Save Entire Process
  115. ;------------------------------------------------
  116.  
  117. SAVPRC  MACRO   TASK
  118.         SAVREGS TASK
  119.      SAVDTA    TASK
  120.      SAV24H    TASK
  121.     SAV23H    TASK
  122.     SAVCUR    TASK
  123.      SAVSCR  TASK
  124.         ENDM
  125.  
  126. ;------------------------------------------------
  127. ; SAVPAG - Save current video page to TCB
  128. ;------------------------------------------------
  129.  
  130. SAVPAG    MACRO    TASK
  131.     mov    bx, 0
  132.     push    bx
  133.     pop    es            ;set segment
  134.     mov    bx, 0462h        ;page number in low ram
  135.     mov    al, byte ptr es:[bx]    ;get it
  136.     mov    ah, 0
  137.     mov    [TASK+50], ax           ;save it into TCB
  138.     mov    cs:videop, ax        ;move it to our global variable
  139.      call    VIDSEG             ;calculate effective video base
  140.     ENDM
  141.  
  142. ;------------------------------------------------
  143. ; SETPAG - set video page
  144. ;------------------------------------------------
  145.  
  146. SETPAG    MACRO    PG
  147.     mov    ax, PG               ;get value page
  148.     mov    ah, 5            ;set video page function number
  149.     int    10h            ;set it
  150.     ENDM
  151.  
  152. ;------------------------------------------------
  153. ; RESPAG - Restore video page
  154. ;------------------------------------------------
  155.  
  156. RESPAG    MACRO    TASK
  157.     mov    ax,  [TASK+50]        ;get value of this processes page
  158.     mov    cs:videop, ax           ;save it into our variable
  159.     mov    ah, 5            ;set video page function number
  160.     int    10h            ;set it
  161.     call     VIDSEG            ;calculate video base
  162.     ENDM
  163.  
  164. ;------------------------------------------------
  165. ; SAVMOD - Save Video Mode To Tcb
  166. ;------------------------------------------------
  167.  
  168. SAVMOD    MACRO    TASK
  169.     mov    bx, 0
  170.     push    bx
  171.     pop    es            ;set segment 0
  172.     mov    bx, 0449h        ;set offset
  173.     mov    al, es:[bx]        ;get video mode
  174.     mov    ah, 0            ;clear ah
  175.     mov    [TASK+40], ax        ;save it
  176.     mov    cs:videom, ax        ;place in global mode variable
  177.     ENDM
  178.  
  179. ;------------------------------------------------
  180. ; RESMOD - Restore Video Mode
  181. ;------------------------------------------------
  182.  
  183. RESMOD    MACRO    TASK
  184.     LOCAL    resmod1
  185.     mov    ax, [tsrprg+40]        ;compare our video modes
  186.     cmp    ax, [dosprg+40]        ;if not different don't switch
  187.     je    resmod1            ;because mode swith is unaesthetic
  188.     mov    ax, [TASK+40]        ;set mode number from TCB
  189.     mov    cs:videom, ax        ;place in global mode variable
  190.     mov    ah, 0            ;set video mode function number
  191.     int    10h            ;call bios
  192.  
  193. resmod1:
  194.  
  195.     ENDM
  196.  
  197. ;------------------------------------------------
  198. ; LODTCK Load tasks tick allocation
  199. ;------------------------------------------------
  200.  
  201. LODTCK    MACRO    TASK
  202.     push    [TASK+44]        ;get it's ticks
  203.     pop    cs:period        ;load them into master timer
  204.     ENDM
  205.  
  206. ;------------------------------------------------
  207. ; SAVSCR - SAVE SCREEN CONTENTS TO BUFFER
  208. ;------------------------------------------------
  209.  
  210. SAVSCR    MACRO    TASK
  211.     LOCAL    LB1, LB2, LB3, LB4
  212.     mov    ax, cs:scrswp    ;get screen swap parameter
  213.     and    ax, 2        ;is save screen bit set?
  214.     jnz    LB4        ;yes then swap 'em
  215.                 ;else ...
  216.     mov    ax, cs:scrswp    ;check again for swap by key
  217.     and    ax, 16        ;save if swap by key?
  218.     jz    LB1        ;no, then exit outta here
  219.                 ;else ...
  220.     cmp    cs:keyswap, 1    ;was swap done by key?
  221.     jne     LB1        ;no, then exit.
  222. LB4:
  223.     SAVMOD    TASK        ;save video mode
  224.      SAVPAG    TASK        ;save video page
  225.     push    ds        ;duck ds!
  226.     push    cs        ;get cs into es
  227.     pop    es
  228.     mov    di, [TASK+42]    ;set destination offset
  229.     mov    ds, cs:videos    ;set source segment
  230.     mov    si, 0        ;set source offset
  231.     mov    cx, cs:videosz    ;initialize count
  232.     cld
  233. rep    movsb            ;buffer transfer
  234.  
  235.     pop    ds        ;restore ds
  236. LB1:
  237.     ENDM
  238.  
  239. ;--------------------------------------------------
  240. ; RESSCR - Restore screen from buffer to video ram
  241. ;--------------------------------------------------
  242.  
  243. RESSCR    MACRO    TASK
  244.     LOCAL    LB1, LB2, LB3, LB4, SNOW1, SNOW2, NOSNOW
  245.     mov    ax, cs:scrswp    ;get screen swap mode
  246.     and    ax, 4        ;is screen restoration enabled?
  247.     jnz    LB4        ;yes? do it
  248.     mov    ax, cs:scrswp    ;check again for swap by key
  249.     and    ax, 32        ;save if swap by key?
  250.     jz    LB1        ;no, then exit outta here
  251.     cmp    cs:keyswap, 1    ;was swap done by key?
  252.     jne     LB1        ;no, then exit.
  253. LB4:
  254.      RESMOD    TASK        ;restore video mode
  255.      RESPAG    TASK        ;restore video page
  256.     push    ds        ;duck ds!
  257.     push    cs        ;get cs into ds
  258.     pop    ds
  259.     mov    si, [TASK+42]    ;set source offset, assume cs seg
  260.     mov    es, cs:videos    ;set destination segment
  261.     mov    di, 0        ;set destination offset
  262.     mov    cx, cs:videosz    ;initialize count
  263.     mov    ax, cs:scrswp
  264.     and    ax, 256        ;check for snow/no snow option
  265.     jnz    NOSNOW
  266.     cld
  267.     mov    dx, 03dah    ;address of video controller
  268. SNOW1:
  269.     in    al, dx
  270.     and    al, 1
  271.     jnz    SNOW1
  272. SNOW2:
  273.     in    al, dx
  274.     and    al, 1
  275.     jz    SNOW2
  276.         movsb            ;buffer transfer
  277.     loop    SNOW1
  278.     pop    ds        ;restore ds
  279.     jmp    LB1
  280.  
  281. NOSNOW:
  282.     cld
  283. rep    movsb
  284.     pop    ds
  285. LB1:
  286.     ENDM
  287.  
  288. ;------------------------------------------------
  289. ; RES23H - Restore Control Break Handler
  290. ;------------------------------------------------
  291.  
  292. RES23h    MACRO    TASK
  293.     SETINT    23h, [TASK+46], [TASK+48]
  294.     ENDM
  295.  
  296. ;------------------------------------------------
  297. ; RESREGS - Restore 8086